package practice.library.gremlin_scala

import java.io.File

import com.thinkaurelius.titan.core.{TitanFactory, TitanGraph}
import org.apache.commons.configuration.BaseConfiguration

import scala.io.Source
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy.VerificationStrategy
import practice.library.gremlin_scala.example.TitanServer

/**
  * Created by lovepocky(lovepocky@foxmail.com) on 2016/6/2.
  */
object GremlinScalaMain {
	//val graphConnect: TitanGraph = TitanFactory.open("src/main/resources/titan/titan-cassandra-es-192.168.1.160.properties")
	
	//val graphConnect = TitanFactory.open("cassandrathrift:192.168.1.160")
	
	/*val conf = new BaseConfiguration()
	conf.setProperty("storage.backend", "inmemory")
	val graphConnect = TitanFactory.open(conf)*/
	
	def main(args: Array[String]): Unit = {
		titanServerPractice()

		
	}
	
	def titanServerPractice() = {
		println("titanServerPractice Start")
		import gremlin.scala._
		import utility.CustomGremlinUtility._
		val graph = TitanServer.connect().asScala
		try {
			val graphVCount = graph.V.count
			val allVertex = graph.V
			val allEdge = graph.E
			
			println(s"graph.V.count : ${graphVCount.head() }")
			
			println("graph.V : ")
			allVertex.toList().foreach(it => println(s"vertex : $it, valueMap : ${it.valueMap }"))
			
			val saturn = graph.V.has(Key[String]("name"), "saturn").head()
			println("graph.V.has(Key[String](\"name\"), \"saturn\") :" + s"${saturn }")
			
			println(s"saturn.valueMap : ${saturn.valueMap }")
			
			val grandchildOfSaturn = saturn.in("father").in("father").headOption().flatMap(_.valueOption("name"))
			println("saturn.in(\"father\").in(\"father\") : " + s"${grandchildOfSaturn }")
			
			
			val placeEdge = graph.E.has(Key[String]("place")).toList()
			println("graph.E.has(Key[String](\"place\")) : ")
			placeEdge.map(it => (it, it.inVertex().valueMap)).foreach(println)
			
		} catch {
			case e: Exception => throw e
		} finally {
			graph.close()
			println("titanServerPractice End")
		}
	}
	
	def gephiTest() = {
		import gremlin.scala._
		val graph = TitanServer.connect().asScala
		try {
			
		} catch {
			case e: Exception => throw e
		} finally {
			graph.close()
		}
	}
}
	

